#include <stdio.h>
#include <windows.h>
#include <Lmcons.h> // for UNLEN

int main()
{
	char computer_name_buffer[MAX_COMPUTERNAME_LENGTH + 1];
	DWORD computer_name_buffer_size = MAX_COMPUTERNAME_LENGTH + 1;
	GetComputerName(computer_name_buffer, &computer_name_buffer_size);
	printf("%s\n", computer_name_buffer);


	char user_name_buffer[UNLEN + 1];
	DWORD user_name_buffer_size = UNLEN + 1;
	GetUserName(user_name_buffer, &user_name_buffer_size);
	printf("%s\n", user_name_buffer);


	int system_directory_buffer_size = GetSystemDirectory(NULL, 0); // 第一次调用仅为了获得所需的缓冲区大小
	char* system_directory_buffer = new char[system_directory_buffer_size];
	GetSystemDirectory(system_directory_buffer, system_directory_buffer_size); // 第二次调用才是真正获得系统目录
	printf("%s\n", system_directory_buffer);
	delete[] system_directory_buffer;
	system_directory_buffer = NULL;


	char windows_directory_buffer[MAX_PATH];
	GetWindowsDirectory(windows_directory_buffer, MAX_PATH);
	printf("%s\n", windows_directory_buffer);


	char* environment_string = "%PATH%";
	int environment_string_expanded_size = ExpandEnvironmentStrings(environment_string, NULL, 0); // 第一次
	char* environment_string_expanded = new char[environment_string_expanded_size];
	ExpandEnvironmentStrings(environment_string, environment_string_expanded, environment_string_expanded_size); // 第二次
	printf("%s\n", environment_string_expanded);
	delete environment_string_expanded;
	environment_string_expanded = NULL;

	
	OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
	printf("%d.%d %s\n", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion);
	return 0;
}
